#include "Queue.h"
void QInit(Queue* pq)
{
	assert(pq);
	pq->phead = pq->ptail = NULL;
	pq->size = 0;
}

void QPush(Queue* pq,QueueDatatype x)
{
	QNode* node = (QNode*)malloc(sizeof(QNode));
	if (node == NULL)
	{
		perror("malloc");
		return;
	}
	node->data = x;
	node->next = NULL;
	if (pq->phead == NULL)
	{
		pq->phead = pq->ptail = node;
	}
	else
	{
		pq->ptail->next = node;
		pq->ptail = pq->ptail->next;
	}
	pq->size++;
}

int QEmpty(Queue* pq)
{
	assert(pq);
	return pq->size == 0;
}

QueueDatatype QueueFront(Queue* pq)
{
	assert(!QEmpty(pq));
	return pq->phead->data;
}

QueueDatatype QueueBack(Queue* pq)
{
	assert(!QEmpty(pq));
	return pq->ptail->data;
}

void QDstroy(Queue* pq)
{
	assert(pq);
	QNode* pcur = pq->phead;
	while (pcur)
	{
		QNode* next = pcur->next;
		free(pcur);
		pcur = next;
	}
	pq->phead = pq->ptail = NULL;
	pq->size = 0;
}
